package 博客Test;

import java.util.ArrayList;
import java.util.Collections;

public class Test2 {
    public static void main(String[] args) {
        // 年龄给出无序
        Student s1 = new Student("兽宝一号",23);
        Student s2 = new Student("兽宝二号",10);
        Student s3 = new Student("兽宝三号",18);
        Student s4 = new Student("兽宝四号",35);

        // 这里用集合来讲,如果又不会的,直接用上面的代码也没问题
        ArrayList<Student> al = new ArrayList<>();

        //Collections 集合工具类 在这里调用了添加方法
        Collections.addAll(al,s1,s2,s3,s4);

        for (int i = 0; i < al.size(); i++) {
            Student stu = al.get(i);
            System.out.println("name = "+stu.name+" age = "+stu.age);
        }

    }
}
